import { defineStore } from 'pinia'

import {
  getAmountListData,
  getGoodsCategoryCount,
  getGoodsCategorySale,
  getGoodsCategoryFavor,
  getGoodsAddressSale
} from '@/service/main/analysis'

import type {
  amountListDaum,
  categoryCountDaum,
  categorySaleDaum,
  favorDaum,
  addressSaleDaum
} from '@/types/analysis'

interface IAnalysisState {
  amountList: amountListDaum[]
  goodsCateGoryCount: categoryCountDaum[]
  goodsCategorySale: categorySaleDaum[]
  goodsCategoryFavor: favorDaum[]
  goodsAddressSale: addressSaleDaum[]
}

const useAnalysisStore = defineStore('analysis', {
  state: (): IAnalysisState => ({
    amountList: [],
    goodsCateGoryCount: [],
    goodsCategorySale: [],
    goodsCategoryFavor: [],
    goodsAddressSale: []
  }),
  actions: {
    async fetchAnalysisDataAcation() {
      const amountResult = (await getAmountListData()).data
      const goodsCateGoryCount = (await getGoodsCategoryCount()).data
      const goodsCategorySale = (await getGoodsCategorySale()).data
      const goodsCateGoryFavor = (await getGoodsCategoryFavor()).data
      const goodsAddressSale = (await getGoodsAddressSale()).data

      this.amountList = amountResult
      this.goodsCateGoryCount = goodsCateGoryCount
      this.goodsCategorySale = goodsCategorySale
      this.goodsCategoryFavor = goodsCateGoryFavor
      this.goodsAddressSale = goodsAddressSale
    }
  }
})

export default useAnalysisStore
